﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsLinq
{

    public partial class FormCountries : Form
    {
        private CountriesTownsDataContext dataContext = null;

        public FormCountries()
        {
            InitializeComponent();
        }

        private void buttonPrevious_Click(object sender, EventArgs e)
        {
            this.countriesBindingSource.MovePrevious();
        }

        private void buttonNext_Click(object sender, EventArgs e)
        {
            this.countriesBindingSource.MoveNext();
        }

        private void FormCountries_Load(object sender, EventArgs e)
        {
            dataContext = new CountriesTownsDataContext();
           // listBoxContinents.DataSource = dataContext.Continents;
           this.continentBindingSource.DataSource = dataContext.Continents;
           //this.countryBindingSource.DataSource = dataContext.Countries;
           // listBoxContinents.DataSource = this.continentBindingSource.DataSource;
           // listBoxContinents.DisplayMember = "";
        }

        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            SaveChanges();
        }

        private void SaveChanges()
        {
            try
            {
                this.dataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
                this.dataContext = new CountriesTownsDataContext();
                this.continentBindingSource.DataSource = dataContext.Countries;
        }

        private void listBoxContinents_SelectedValueChanged(object sender, EventArgs e)
        {
          //  int continentId = (int)this.listBoxContinents.SelectedValue;
          //  countryBindingSource.DataSource=dataContext.Countries.Where(p=>p.ContinentId==continentId);
        }


    }
}
